package domain;

import java.util.*;
import entities.concept.AndConcept;
import entities.concept.Concept;
import entities.concept.DomainConcept;
import entities.concept.DomainConceptEQ;
import entities.concept.DomainConceptLT;
import entities.concept.DomainConceptLTEQ;
import entities.role.Role;

/**
 * This class builds a feature concept graph to determine the clashes.
 * with three operators, there are 8 cases to consider clashes (in fact seven as it is impossible to have no ops)
 * a path with all <: clash
 * a path with all <=: no
 * all =: no
 * = <=: no
 * < <=: clash
 * < =: clash
 * < = <=: clash
 * hence: when no (less than <) is present in the path, there will be no clash!
 * 
 * for equality clash: f=k1 and f=k2, use a different method
 * 
 * NB. when add f=g, must add g=f;
 * @author Enoch
 *
 */
public class TestGraph {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Role f =new Role("f");
		//String f = "f";
		//String g = "3";
		Role g = new Role("g");
		//String k = "2";
		//Role k = new Role("k");
		//String l = "2";
		//Role l = new Role("l");
		
		//DomainConceptLTEQ a = new DomainConceptLTEQ(f,g);
		//DomainConceptLTEQ b = new DomainConceptLTEQ(g,l);
		//DomainConceptLTEQ c = new DomainConceptLTEQ(l,f);
		DomainConceptLTEQ<Role, Integer> d = new DomainConceptLTEQ<Role, Integer>(f,2);
		DomainConceptEQ<Role, Integer> e = new DomainConceptEQ<Role, Integer>(g,0);
		DomainConceptLTEQ<Role, Role> s1 = new DomainConceptLTEQ<Role, Role>(g,f);
		//DomainConceptEQ s2 = new DomainConceptEQ(l,"002");
		//DomainConceptLT a2 = new DomainConceptLT(f,l);
		
		HashSet<DomainConcept<?, ?>> s = new HashSet<DomainConcept<?,?>>();
		//s.add(a);
		//s.add(b);
	//	s.add(c);
		s.add(d);
		s.add(e);
		s.add(s1);
		//s.add(s2);
		//s.add(a2);
		FeatureGraph fg = new FeatureGraph();
		fg.buildGraph(s);
		if(fg.clashFinder()){
			System.out.println("\nClash found");
		}else{
			System.out.println("\n No Clash found");
		}
		
		//Concept aa=new PConcept("A");
		//Concept bb=new PConcept("A");
		Concept aa=new DomainConceptLT<Role, String>(new Role("R"), "s555");
		Concept bb=new DomainConceptLT<Role, String>(new Role("R"), "555");
		HashSet<Concept> set1 = new HashSet<Concept>();
		set1.add(aa);
		set1.add(bb);
		Concept and1 = new AndConcept(set1);
		HashSet<Concept> set2 = new HashSet<Concept>();
		set2.add(aa);
		set2.add(bb);
		Concept and2 = new AndConcept(set2);
		HashSet<Concept> c1 = new HashSet<Concept>();
		c1.add(and1);
		HashSet<Concept> c2 = new HashSet<Concept>();
		c2.add(and2);
		
		if(Collections.disjoint(c1, c2)){
			System.out.println("disjoint");
		}else{
			System.out.println("common elements found");
		}
		/*for(Vertex v:fg.vertices){
			System.out.println("Now testing: "+v.renderDomainObject());
			if(v.computeEQClash(v)) 
				System.out.println("clash");
			else{
				System.out.println("no clash");
			}
			String eq = "\n"+v.renderDomainObject() + " equals to: ";
			for(Vertex vv:v.equivalenceSet){
				eq += vv.renderDomainObject()+"; ";
			}
			System.out.println(eq);
		}*/
	}

}
